var publishMAppList = {
    account:'',
	load : function () {
		Ext.QuickTips.init();
		this.createGrid(); //建立 Ext table
		var qs =  new QueryString();
		publishMAppList.account = qs.get("account");

	},
  
	createGrid : function () {
		var qs =  new QueryString();
		var account = qs.get("account");
		
		var store = new Ext.data.JsonStore ({
			 proxy: new Ext.data.HttpProxy({  
		            method: 'GET',  
		            url:"/ad/sys/com/control/publish/AppInfoService.php?action=getAppInfoList&account="+account//getUser().Account,
//		            ,extraParams: {"dateEnd" : new Date().format('Y-m-d')}  
		        }),
			root : "row", 
			remoteSort: true,
			totalProperty: 'count',
			fields : ["createtime","name","id","status","md5key"]
		});
		
		 
		var grid =new Ext.grid.GridPanel({
			renderTo : "grid",
			store :  store,
			height: 330,
			loadMask : true,
			viewConfig : {
				forceFit : true 
			},
			columns : [ 
				new Ext.grid.RowNumberer(),
				{header : "應用程式名稱", dataIndex : "name" , width : 150, sortable : true,
					renderer:function (value , p, record){
					
					return "<a href='/ad/sys/com/control/publish/AppInfoService.php?action=getAppInfoDetail&id=" +
					record.data.id+"'>"+value+"</a>";
					
				}},
				{header : "狀態", dataIndex : "status" , width : 80, sortable : true,
					renderer:function (value , p, record){
						switch(value)
						{
							case '1':
								return '審理中 ';
							case '2':
								return '停用中 ';
							case '3':
								return '測試中 ';
							case '4':
								return '使用中 ';
							default:
								return value;
						}
					}
},
				{header : "建立時間", dataIndex : "createtime" , width : 181, sortable : true},
				{header : "Key", dataIndex : "md5key" , width : 166, sortable : true},
				{header : "平台類別", dataIndex : "name" , width : 83, sortable : true,
					renderer:function (value , p, record){
						return  value==1?'Android':'iPhone';
					}
				},
				{header : "管理", dataIndex : "id" , width : 83, sortable : true,
					renderer:function (value , p, record){
		    			if(publishMAppList.account!=null && publishMAppList.account.length>0)
		    				value=value+'&account='+publishMAppList.account;

						return  '<a href="/ad/html/publish/publishMAppDetailUpdate.php?id='+value+'">管理</a>';
					}
				}
			],
			
			bbar : new Ext.PagingToolbar({
				pageSize :20,
				store : store,
				displayInfo : true,
				displayMsg : "顯示第 {0} 筆到 {1} 筆紀錄,共 {2} 筆紀錄",
				emptyMsg : "沒有紀錄" 
			})
		});	
		
		store.load({
			params:{
				"start":0,
				"limit":20
			}
		});    
	}
	 
};

Ext.onReady(function (){
	publishMAppList.load();
});